using System;
using System.Collections.Generic;
using System.ComponentModel.Design;
using System.Diagnostics;
using System.IO;
using System.Windows.Forms;
using System.Xml;
using TmxLib;

namespace TmxEditor
{
    static class Program
    {
        /// <summary>
        /// The main entry point for the application.
        /// </summary>
        [STAThread]
        static void Main(string[] args)
        {
            Debug.WriteLine(Environment.Version);
            
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            // TestDesigner(); return;
            

            string file;
            if (args.Length >= 1)
            {
                file = args[0];
            }
            else
            {
                OpenFileDialog ofd = new OpenFileDialog();
                ofd.CheckFileExists = true;
                ofd.DefaultExt = "tmx";
                ofd.Filter = "Translation Memory Exchange (*.tmx)|*.tmx|All Files|*.*";
                ofd.Title = "Open Translation Project";
                if (ofd.ShowDialog() == DialogResult.OK)
                {
                    file = ofd.FileName;
                }
                else
                {
                    return;
                }
            }

            XmlDocument doc = new XmlDocument();
            doc.Load(file);
            TmxImage tmx = TmxReader.Parse(doc);
            string tmxName = new FileInfo(file).FullName;

            Application.Run(new TmxEditorForm(tmx, tmxName));
        }

        static void TestDesigner()
        {
            DesignSurface ds = new DesignSurface();
            ds.BeginLoad(typeof(TmxEditorForm));

            // Get the View of the DesignSurface, host it in a form, and show it
            Control c = ds.View as Control;
            Form f = new Form();
            c.Parent = f;
            c.Dock = DockStyle.Fill;
            Application.Run(f);
        }
    }
}